import store from '@/store'

export default {
    // 被绑定元素插入父节点时调用
    inserted(el, binding) {
        const { value } = binding
        const buttonList = store.getters && store.getters.buttonList
        if (value) {
            const hasPermission = buttonList.some(button => {
                return button === value
            })

            if (!hasPermission) {
                el.parentNode && el.parentNode.removeChild(el)
            }
        } else {
            throw new Error('需要指定权限标识！如 v-permission="article:add"')
        }
    }

}